<!DOCTYPE html>
<html lang="zh" dir="ltr" class="client-nojs">
<head>
<title>std::atomic</title>
<meta charset="UTF-8">
<meta name="generator" content="MediaWiki 1.21.2">
<link rel="shortcut icon" href="../../../common/favicon.ico">
<link rel="stylesheet" href="../../../common/ext.css">
<meta name="ResourceLoaderDynamicStyles" content="">
<link rel="stylesheet" href="../../../common/site_modules.css">
<style>a:lang(ar),a:lang(ckb),a:lang(fa),a:lang(kk-arab),a:lang(mzn),a:lang(ps),a:lang(ur){text-decoration:none}#toc{display:none}.editsection{display:none}
/* cache key: mwiki1-mwiki_zh_:resourceloader:filter:minify-css:7:15cea3ec788a65b5187d4018eed543bf */</style>

<script src="../../../common/startup_scripts.js"></script>
<script>if(window.mw){
mw.config.set({"wgCanonicalNamespace":"","wgCanonicalSpecialPageName":false,"wgNamespaceNumber":0,"wgPageName":"cpp/atomic/atomic","wgTitle":"cpp/atomic/atomic","wgCurRevisionId":64593,"wgArticleId":1490,"wgIsArticle":true,"wgAction":"view","wgUserName":null,"wgUserGroups":["*"],"wgCategories":["Pages with unreviewed LWG DR marker"],"wgBreakFrames":false,"wgPageContentLanguage":"zh","wgSeparatorTransformTable":["",""],"wgDigitTransformTable":["",""],"wgDefaultDateFormat":"zh","wgMonthNames":["","1月","2月","3月","4月","5月","6月","7月","8月","9月","10月","11月","12月"],"wgMonthNamesShort":["","1月","2月","3月","4月","5月","6月","7月","8月","9月","10月","11月","12月"],"wgRelevantPageName":"cpp/atomic/atomic","wgUserVariant":"zh","wgRestrictionEdit":[],"wgRestrictionMove":[]});
}</script><script>if(window.mw){
mw.loader.implement("user.options",function(){mw.user.options.set({"ccmeonemails":0,"cols":80,"date":"default","diffonly":0,"disablemail":0,"disablesuggest":0,"editfont":"default","editondblclick":0,"editsection":0,"editsectiononrightclick":0,"enotifminoredits":0,"enotifrevealaddr":0,"enotifusertalkpages":1,"enotifwatchlistpages":0,"extendwatchlist":0,"externaldiff":0,"externaleditor":0,"fancysig":0,"forceeditsummary":0,"gender":"unknown","hideminor":0,"hidepatrolled":0,"imagesize":2,"justify":0,"math":1,"minordefault":0,"newpageshidepatrolled":0,"nocache":0,"noconvertlink":0,"norollbackdiff":0,"numberheadings":0,"previewonfirst":0,"previewontop":1,"quickbar":5,"rcdays":7,"rclimit":50,"rememberpassword":0,"rows":25,"searchlimit":20,"showhiddencats":0,"showjumplinks":1,"shownumberswatching":1,"showtoc":0,"showtoolbar":1,"skin":"cppreference2","stubthreshold":0,"thumbsize":2,"underline":2,"uselivepreview":0,"usenewrc":0,"watchcreations":0,"watchdefault":0,"watchdeletion":0,
"watchlistdays":3,"watchlisthideanons":0,"watchlisthidebots":0,"watchlisthideliu":0,"watchlisthideminor":0,"watchlisthideown":0,"watchlisthidepatrolled":0,"watchmoves":0,"wllimit":250,"variant":"zh","language":"zh","searchNs0":true,"searchNs1":false,"searchNs2":false,"searchNs3":false,"searchNs4":false,"searchNs5":false,"searchNs6":false,"searchNs7":false,"searchNs8":false,"searchNs9":false,"searchNs10":false,"searchNs11":false,"searchNs12":false,"searchNs13":false,"searchNs14":false,"searchNs15":false,"gadget-MathJax":1,"gadget-ColiruCompiler":1});;},{},{});mw.loader.implement("user.tokens",function(){mw.user.tokens.set({"editToken":"+\\","patrolToken":false,"watchToken":false});;},{},{});
/* cache key: mwiki1-mwiki_zh_:resourceloader:filter:minify-js:7:258d7cd6aa9aa67dee25e01fb6a9e505 */
}</script>
<script>if(window.mw){
mw.loader.load(["mediawiki.page.startup","mediawiki.legacy.wikibits","mediawiki.legacy.ajax"]);
}</script>
<style type="text/css">/*<![CDATA[*/
.source-cpp {line-height: normal;}
.source-cpp li, .source-cpp pre {
	line-height: normal; border: 0px none white;
}
/**
 * GeSHi Dynamically Generated Stylesheet
 * --------------------------------------
 * Dynamically generated stylesheet for cpp
 * CSS class: source-cpp, CSS id: 
 * GeSHi (C) 2004 - 2007 Nigel McNie, 2007 - 2008 Benny Baumann
 * (http://qbnz.com/highlighter/ and http://geshi.org/)
 * --------------------------------------
 */
.cpp.source-cpp .de1, .cpp.source-cpp .de2 {font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;}
.cpp.source-cpp  {font-family:monospace;}
.cpp.source-cpp .imp {font-weight: bold; color: red;}
.cpp.source-cpp li, .cpp.source-cpp .li1 {font-weight: normal; vertical-align:top;}
.cpp.source-cpp .ln {width:1px;text-align:right;margin:0;padding:0 2px;vertical-align:top;}
.cpp.source-cpp .li2 {font-weight: bold; vertical-align:top;}
.cpp.source-cpp .kw1 {color: #0000dd;}
.cpp.source-cpp .kw2 {color: #0000ff;}
.cpp.source-cpp .kw3 {color: #0000dd;}
.cpp.source-cpp .kw4 {color: #0000ff;}
.cpp.source-cpp .co1 {color: #909090;}
.cpp.source-cpp .co2 {color: #339900;}
.cpp.source-cpp .coMULTI {color: #ff0000; font-style: italic;}
.cpp.source-cpp .es0 {color: #008000; font-weight: bold;}
.cpp.source-cpp .es1 {color: #008000; font-weight: bold;}
.cpp.source-cpp .es2 {color: #008000; font-weight: bold;}
.cpp.source-cpp .es3 {color: #008000; font-weight: bold;}
.cpp.source-cpp .es4 {color: #008000; font-weight: bold;}
.cpp.source-cpp .es5 {color: #008000; font-weight: bold;}
.cpp.source-cpp .br0 {color: #008000;}
.cpp.source-cpp .sy0 {color: #008000;}
.cpp.source-cpp .sy1 {color: #000080;}
.cpp.source-cpp .sy2 {color: #000040;}
.cpp.source-cpp .sy3 {color: #000040;}
.cpp.source-cpp .sy4 {color: #008080;}
.cpp.source-cpp .st0 {color: #008000;}
.cpp.source-cpp .nu0 {color: #000080;}
.cpp.source-cpp .nu6 {color: #000080;}
.cpp.source-cpp .nu8 {color: #000080;}
.cpp.source-cpp .nu12 {color: #000080;}
.cpp.source-cpp .nu16 {color:#000080;}
.cpp.source-cpp .nu17 {color:#000080;}
.cpp.source-cpp .nu18 {color:#000080;}
.cpp.source-cpp .nu19 {color:#000080;}
.cpp.source-cpp .ln-xtra, .cpp.source-cpp li.ln-xtra, .cpp.source-cpp div.ln-xtra {background-color: #ffc;}
.cpp.source-cpp span.xtra { display:block; }

/*]]>*/
</style><!--[if lt IE 7]><style type="text/css">body{behavior:url("/mwiki/skins/cppreference2/csshover.min.htc")}</style><![endif]--></head>
<body class="mediawiki ltr sitedir-ltr ns-0 ns-subject page-cpp_atomic_atomic skin-cppreference2 action-view cpp-navbar">
        <!-- header -->
        <!-- /header -->
        <!-- content -->
<div id="cpp-content-base">
            <div id="content">
                <a id="top"></a>
                <div id="mw-js-message" style="display:none;"></div>
                                <!-- firstHeading -->
<h1 id="firstHeading" class="firstHeading"><span style="font-size:0.7em; line-height:130%">std::</span>atomic</h1>
                <!-- /firstHeading -->
                <!-- bodyContent -->
                <div id="bodyContent">
                                        <!-- tagline -->
                    <div id="siteSub">来自cppreference.com</div>
                    <!-- /tagline -->
                                        <!-- subtitle -->
                    <div id="contentSub"><span class="subpages">&lt; <a href="../../cpp.html" title="cpp">cpp</a>‎ | <a href="../atomic.html" title="cpp/atomic">atomic</a></span></div>
                    <!-- /subtitle -->
                                                            <!-- bodycontent -->
                    <div id="mw-content-text" lang="zh" dir="ltr" class="mw-content-ltr"><div class="t-navbar" style=""><div class="t-navbar-sep"> </div><div class="t-navbar-head"><a href="../../cpp.html" title="cpp"> C++</a><div class="t-navbar-menu"><div><div><table class="t-nv-begin" cellpadding="0" style="line-height:1.1em;">
<tr class="t-nv"><td colspan="5"> <a href="../language.html" title="cpp/language">语言</a> </td></tr>
<tr class="t-nv"><td colspan="5"> <a href="../header.html" title="cpp/header">标准库头文件</a> </td></tr>
<tr class="t-nv"><td colspan="5"> <a href="../freestanding.html" title="cpp/freestanding"> 自立与有宿主实现</a> </td></tr>
<tr class="t-nv"><td colspan="5"> <a href="../named_req.html" title="cpp/named req">具名要求</a> </td></tr>
<tr class="t-nv"><td colspan="5"> <a href="../utility.html#.E8.AF.AD.E8.A8.80.E6.94.AF.E6.8C.81" title="cpp/utility">语言支持库</a> </td></tr>
<tr class="t-nv"><td colspan="5"> <a href="../concepts.html" title="cpp/concepts">概念库</a> <span class="t-mark-rev t-since-cxx20">(C++20)</span> </td></tr>
<tr class="t-nv"><td colspan="5"> <a href="../error.html" title="cpp/error">诊断库</a> </td></tr>
<tr class="t-nv"><td colspan="5"> <a href="../utility.html" title="cpp/utility">工具库</a> </td></tr>
<tr class="t-nv"><td colspan="5"> <a href="../string.html" title="cpp/string">字符串库</a> </td></tr>
<tr class="t-nv"><td colspan="5"> <a href="https://zh.cppreference.com/w/cpp/container" title="cpp/container">容器库</a> </td></tr>
<tr class="t-nv"><td colspan="5"> <a href="../iterator.html" title="cpp/iterator">迭代器库</a> </td></tr>
<tr class="t-nv"><td colspan="5"> <a href="../ranges.html" title="cpp/ranges"> 范围库</a> <span class="t-mark-rev t-since-cxx20">(C++20)</span> </td></tr>
<tr class="t-nv"><td colspan="5"> <a href="../algorithm.html" title="cpp/algorithm">算法库</a> </td></tr>
<tr class="t-nv"><td colspan="5"> <a href="../numeric.html" title="cpp/numeric">数值库</a> </td></tr>
<tr class="t-nv"><td colspan="5"> <a href="../io.html" title="cpp/io">输入/输出库</a> </td></tr>
<tr class="t-nv"><td colspan="5"> <a href="../locale.html" title="cpp/locale">本地化库</a> </td></tr>
<tr class="t-nv"><td colspan="5"> <a href="../regex.html" title="cpp/regex">正则表达式库</a> <span class="t-mark-rev t-since-cxx11">(C++11)</span> </td></tr>
<tr class="t-nv"><td colspan="5"> <a href="../atomic.html" title="cpp/atomic">原子操作库</a> <span class="t-mark-rev t-since-cxx11">(C++11)</span> </td></tr>
<tr class="t-nv"><td colspan="5"> <a href="../thread.html" title="cpp/thread">线程支持库</a> <span class="t-mark-rev t-since-cxx11">(C++11)</span> </td></tr>
<tr class="t-nv"><td colspan="5"> <a href="../filesystem.html" title="cpp/filesystem">文件系统库</a> <span class="t-mark-rev t-since-cxx17">(C++17)</span> </td></tr>
<tr class="t-nv"><td colspan="5"> <a href="../experimental.html" title="cpp/experimental">技术规范</a> </td></tr>
</table></div><div></div></div></div></div><div class="t-navbar-sep"> </div><div class="t-navbar-head"><a href="../atomic.html" title="cpp/atomic">原子操作库</a><div class="t-navbar-menu"><div><div><table class="t-nv-begin" cellpadding="0" style="">
<tr class="t-nv-h1"><td colspan="5"> 类</td></tr>
<tr class="t-nv"><td colspan="5"><div class="t-nv-ln-table"><div><strong class="selflink"><span class="t-lines"><span>atomic</span></span></strong></div><div><span class="t-lines"><span><span class="t-mark-rev t-since-cxx11">(C++11)</span></span></span></div></div></td></tr>
<tr class="t-nv"><td colspan="5"><div class="t-nv-ln-table"><div><a href="atomic_ref.html" title="cpp/atomic/atomic ref"><span class="t-lines"><span>atomic_ref</span></span></a></div><div><span class="t-lines"><span><span class="t-mark-rev t-since-cxx20">(C++20)</span></span></span></div></div></td></tr>
<tr class="t-nv-h1"><td colspan="5"> 函数</td></tr>
<tr class="t-nv"><td colspan="5"><div class="t-nv-ln-table"><div><a href="atomic_store.html" title="cpp/atomic/atomic store"><span class="t-lines"><span>atomic_store</span><span>atomic_store_explicit</span></span></a></div><div><span class="t-lines"><span><span class="t-mark-rev t-since-cxx11">(C++11)</span></span><span><span class="t-mark-rev t-since-cxx11">(C++11)</span></span></span></div></div></td></tr>
<tr class="t-nv"><td colspan="5"><div class="t-nv-ln-table"><div><a href="atomic_load.html" title="cpp/atomic/atomic load"><span class="t-lines"><span>atomic_load</span><span>atomic_load_explicit</span></span></a></div><div><span class="t-lines"><span><span class="t-mark-rev t-since-cxx11">(C++11)</span></span><span><span class="t-mark-rev t-since-cxx11">(C++11)</span></span></span></div></div></td></tr>
<tr class="t-nv"><td colspan="5"><div class="t-nv-ln-table"><div><a href="atomic_exchange.html" title="cpp/atomic/atomic exchange"><span class="t-lines"><span>atomic_exchange</span><span>atomic_exchange_explicit</span></span></a></div><div><span class="t-lines"><span><span class="t-mark-rev t-since-cxx11">(C++11)</span></span><span><span class="t-mark-rev t-since-cxx11">(C++11)</span></span></span></div></div></td></tr>
<tr class="t-nv"><td colspan="5"><div class="t-nv-ln-table"><div><a href="atomic_compare_exchange.html" title="cpp/atomic/atomic compare exchange"><span class="t-lines"><span>atomic_compare_exchange_weak</span><span>atomic_compare_exchange_weak_explicit</span><span>atomic_compare_exchange_strong</span><span>atomic_compare_exchange_strong_explicit</span></span></a></div><div><span class="t-lines"><span><span class="t-mark-rev t-since-cxx11">(C++11)</span></span><span><span class="t-mark-rev t-since-cxx11">(C++11)</span></span><span><span class="t-mark-rev t-since-cxx11">(C++11)</span></span><span><span class="t-mark-rev t-since-cxx11">(C++11)</span></span></span></div></div></td></tr>
<tr class="t-nv"><td colspan="5"><div class="t-nv-ln-table"><div><a href="atomic_fetch_add.html" title="cpp/atomic/atomic fetch add"><span class="t-lines"><span>atomic_fetch_add</span><span>atomic_fetch_add_explicit</span></span></a></div><div><span class="t-lines"><span><span class="t-mark-rev t-since-cxx11">(C++11)</span></span><span><span class="t-mark-rev t-since-cxx11">(C++11)</span></span></span></div></div></td></tr>
<tr class="t-nv"><td colspan="5"><div class="t-nv-ln-table"><div><a href="atomic_fetch_sub.html" title="cpp/atomic/atomic fetch sub"><span class="t-lines"><span>atomic_fetch_sub</span><span>atomic_fetch_sub_explicit</span></span></a></div><div><span class="t-lines"><span><span class="t-mark-rev t-since-cxx11">(C++11)</span></span><span><span class="t-mark-rev t-since-cxx11">(C++11)</span></span></span></div></div></td></tr>
<tr class="t-nv"><td colspan="5"><div class="t-nv-ln-table"><div><a href="atomic_fetch_and.html" title="cpp/atomic/atomic fetch and"><span class="t-lines"><span>atomic_fetch_and</span><span>atomic_fetch_and_explicit</span></span></a></div><div><span class="t-lines"><span><span class="t-mark-rev t-since-cxx11">(C++11)</span></span><span><span class="t-mark-rev t-since-cxx11">(C++11)</span></span></span></div></div></td></tr>
<tr class="t-nv"><td colspan="5"><div class="t-nv-ln-table"><div><a href="atomic_fetch_or.html" title="cpp/atomic/atomic fetch or"><span class="t-lines"><span>atomic_fetch_or</span><span>atomic_fetch_or_explicit</span></span></a></div><div><span class="t-lines"><span><span class="t-mark-rev t-since-cxx11">(C++11)</span></span><span><span class="t-mark-rev t-since-cxx11">(C++11)</span></span></span></div></div></td></tr>
<tr class="t-nv"><td colspan="5"><div class="t-nv-ln-table"><div><a href="atomic_fetch_xor.html" title="cpp/atomic/atomic fetch xor"><span class="t-lines"><span>atomic_fetch_xor</span><span>atomic_fetch_xor_explicit</span></span></a></div><div><span class="t-lines"><span><span class="t-mark-rev t-since-cxx11">(C++11)</span></span><span><span class="t-mark-rev t-since-cxx11">(C++11)</span></span></span></div></div></td></tr>
<tr class="t-nv"><td colspan="5"><div class="t-nv-ln-table"><div><a href="atomic_is_lock_free.html" title="cpp/atomic/atomic is lock free"><span class="t-lines"><span>atomic_is_lock_free</span></span></a></div><div><span class="t-lines"><span><span class="t-mark-rev t-since-cxx11">(C++11)</span></span></span></div></div></td></tr>
<tr class="t-nv"><td colspan="5"><div class="t-nv-ln-table"><div><a href="atomic_wait.html" title="cpp/atomic/atomic wait"><span class="t-lines"><span>atomic_wait</span><span>atomic_wait_explicit</span></span></a></div><div><span class="t-lines"><span><span class="t-mark-rev t-since-cxx20">(C++20)</span></span><span><span class="t-mark-rev t-since-cxx20">(C++20)</span></span></span></div></div></td></tr>
<tr class="t-nv"><td colspan="5"><div class="t-nv-ln-table"><div><a href="atomic_notify_one.html" title="cpp/atomic/atomic notify one"><span class="t-lines"><span>atomic_notify_one</span></span></a></div><div><span class="t-lines"><span><span class="t-mark-rev t-since-cxx20">(C++20)</span></span></span></div></div></td></tr>
<tr class="t-nv"><td colspan="5"><div class="t-nv-ln-table"><div><a href="atomic_notify_all.html" title="cpp/atomic/atomic notify all"><span class="t-lines"><span>atomic_notify_all</span></span></a></div><div><span class="t-lines"><span><span class="t-mark-rev t-since-cxx20">(C++20)</span></span></span></div></div></td></tr>
<tr class="t-nv-h1"><td colspan="5"> 原子标志</td></tr>
<tr class="t-nv"><td colspan="5"><div class="t-nv-ln-table"><div><a href="atomic_flag.html" title="cpp/atomic/atomic flag"><span class="t-lines"><span>atomic_flag</span></span></a></div><div><span class="t-lines"><span><span class="t-mark-rev t-since-cxx11">(C++11)</span></span></span></div></div></td></tr>
<tr class="t-nv"><td colspan="5"><div class="t-nv-ln-table"><div><a href="atomic_flag_test_and_set.html" title="cpp/atomic/atomic flag test and set"><span class="t-lines"><span>atomic_flag_test_and_set</span><span>atomic_flag_test_and_set_explicit</span></span></a></div><div><span class="t-lines"><span><span class="t-mark-rev t-since-cxx11">(C++11)</span></span><span><span class="t-mark-rev t-since-cxx11">(C++11)</span></span></span></div></div></td></tr>
<tr class="t-nv"><td colspan="5"><div class="t-nv-ln-table"><div><a href="atomic_flag_clear.html" title="cpp/atomic/atomic flag clear"><span class="t-lines"><span>atomic_flag_clear</span><span>atomic_flag_clear_explicit</span></span></a></div><div><span class="t-lines"><span><span class="t-mark-rev t-since-cxx11">(C++11)</span></span><span><span class="t-mark-rev t-since-cxx11">(C++11)</span></span></span></div></div></td></tr>
<tr class="t-nv"><td colspan="5"><div class="t-nv-ln-table"><div><a href="atomic_flag_test.html" title="cpp/atomic/atomic flag test"><span class="t-lines"><span>atomic_flag_test</span><span>atomic_flag_test_explicit</span></span></a></div><div><span class="t-lines"><span><span class="t-mark-rev t-since-cxx20">(C++20)</span></span><span><span class="t-mark-rev t-since-cxx20">(C++20)</span></span></span></div></div></td></tr>
<tr class="t-nv"><td colspan="5"><div class="t-nv-ln-table"><div><a href="atomic_flag_wait.html" title="cpp/atomic/atomic flag wait"><span class="t-lines"><span>atomic_flag_wait</span><span>atomic_flag_wait_explicit</span></span></a></div><div><span class="t-lines"><span><span class="t-mark-rev t-since-cxx20">(C++20)</span></span><span><span class="t-mark-rev t-since-cxx20">(C++20)</span></span></span></div></div></td></tr>
<tr class="t-nv"><td colspan="5"><div class="t-nv-ln-table"><div><a href="atomic_flag_notify_one.html" title="cpp/atomic/atomic flag notify one"><span class="t-lines"><span>atomic_flag_notify_one</span></span></a></div><div><span class="t-lines"><span><span class="t-mark-rev t-since-cxx20">(C++20)</span></span></span></div></div></td></tr>
<tr class="t-nv"><td colspan="5"><div class="t-nv-ln-table"><div><a href="atomic_flag_notify_all.html" title="cpp/atomic/atomic flag notify all"><span class="t-lines"><span>atomic_flag_notify_all</span></span></a></div><div><span class="t-lines"><span><span class="t-mark-rev t-since-cxx20">(C++20)</span></span></span></div></div></td></tr>
<tr class="t-nv-h1"><td colspan="5"> 初始化</td></tr>
<tr class="t-nv"><td colspan="5"><div class="t-nv-ln-table"><div><a href="atomic_init.html" title="cpp/atomic/atomic init"><span class="t-lines"><span>atomic_init</span></span></a></div><div><span class="t-lines"><span><span class="t-mark-rev t-since-cxx11">(C++11)</span><span class="t-mark-rev t-deprecated-cxx20">(C++20 中弃用)</span></span></span></div></div></td></tr>
<tr class="t-nv"><td colspan="5"><div class="t-nv-ln-table"><div><a href="ATOMIC_VAR_INIT.html" title="cpp/atomic/ATOMIC VAR INIT"><span class="t-lines"><span>ATOMIC_VAR_INIT</span></span></a></div><div><span class="t-lines"><span><span class="t-mark-rev t-since-cxx11">(C++11)</span><span class="t-mark-rev t-deprecated-cxx20">(C++20 中弃用)</span></span></span></div></div></td></tr>
<tr class="t-nv"><td colspan="5"><div class="t-nv-ln-table"><div><a href="ATOMIC_FLAG_INIT.html" title="cpp/atomic/ATOMIC FLAG INIT"><span class="t-lines"><span>ATOMIC_FLAG_INIT</span></span></a></div><div><span class="t-lines"><span><span class="t-mark-rev t-since-cxx11">(C++11)</span><span class="t-mark-rev t-deprecated-cxx20">(C++20 中弃用)</span></span></span></div></div></td></tr>
<tr class="t-nv-h1"><td colspan="5"> 内存顺序</td></tr>
<tr class="t-nv"><td colspan="5"><div class="t-nv-ln-table"><div><a href="memory_order.html" title="cpp/atomic/memory order"><span class="t-lines"><span>memory_order</span></span></a></div><div><span class="t-lines"><span><span class="t-mark-rev t-since-cxx11">(C++11)</span></span></span></div></div></td></tr>
<tr class="t-nv"><td colspan="5"><div class="t-nv-ln-table"><div><a href="kill_dependency.html" title="cpp/atomic/kill dependency"><span class="t-lines"><span>kill_dependency</span></span></a></div><div><span class="t-lines"><span><span class="t-mark-rev t-since-cxx11">(C++11)</span></span></span></div></div></td></tr>
<tr class="t-nv"><td colspan="5"><div class="t-nv-ln-table"><div><a href="atomic_thread_fence.html" title="cpp/atomic/atomic thread fence"><span class="t-lines"><span>atomic_thread_fence</span></span></a></div><div><span class="t-lines"><span><span class="t-mark-rev t-since-cxx11">(C++11)</span></span></span></div></div></td></tr>
<tr class="t-nv"><td colspan="5"><div class="t-nv-ln-table"><div><a href="atomic_signal_fence.html" title="cpp/atomic/atomic signal fence"><span class="t-lines"><span>atomic_signal_fence</span></span></a></div><div><span class="t-lines"><span><span class="t-mark-rev t-since-cxx11">(C++11)</span></span></span></div></div></td></tr>
</table></div><div></div></div></div></div><div class="t-navbar-sep"> </div><div class="t-navbar-head"><strong class="selflink"><tt>std::atomic</tt></strong><div class="t-navbar-menu"><div><div><table class="t-nv-begin" cellpadding="0" style="">
<tr class="t-nv-h1"><td colspan="5"> 成员函数</td></tr>
<tr class="t-nv"><td colspan="5"><div class="t-nv-ln-table"><div><a href="atomic/atomic.html" title="cpp/atomic/atomic/atomic"><span class="t-lines"><span>atomic::atomic</span></span></a></div></div></td></tr>
<tr class="t-nv"><td colspan="5"><div class="t-nv-ln-table"><div><a href="atomic/operator%3D.html" title="cpp/atomic/atomic/operator="><span class="t-lines"><span>atomic::operator=</span></span></a></div></div></td></tr>
<tr class="t-nv"><td colspan="5"><div class="t-nv-ln-table"><div><a href="atomic/is_lock_free.html" title="cpp/atomic/atomic/is lock free"><span class="t-lines"><span>atomic::is_lock_free</span></span></a></div></div></td></tr>
<tr class="t-nv"><td colspan="5"><div class="t-nv-ln-table"><div><a href="atomic/store.html" title="cpp/atomic/atomic/store"><span class="t-lines"><span>atomic::store</span></span></a></div></div></td></tr>
<tr class="t-nv"><td colspan="5"><div class="t-nv-ln-table"><div><a href="atomic/load.html" title="cpp/atomic/atomic/load"><span class="t-lines"><span>atomic::load</span></span></a></div></div></td></tr>
<tr class="t-nv"><td colspan="5"><div class="t-nv-ln-table"><div><a href="atomic/operator_T.html" title="cpp/atomic/atomic/operator T"><span class="t-lines"><span>atomic::operator T</span></span></a></div></div></td></tr>
<tr class="t-nv"><td colspan="5"><div class="t-nv-ln-table"><div><a href="atomic/exchange.html" title="cpp/atomic/atomic/exchange"><span class="t-lines"><span>atomic::exchange</span></span></a></div></div></td></tr>
<tr class="t-nv"><td colspan="5"><div class="t-nv-ln-table"><div><a href="atomic/compare_exchange.html" title="cpp/atomic/atomic/compare exchange"><span class="t-lines"><span>atomic::compare_exchange_strong</span><span>atomic::compare_exchange_weak</span></span></a></div></div></td></tr>
<tr class="t-nv"><td colspan="5"><div class="t-nv-ln-table"><div><a href="atomic/wait.html" title="cpp/atomic/atomic/wait"><span class="t-lines"><span>atomic::wait</span></span></a></div><div><span class="t-lines"><span><span class="t-mark-rev t-since-cxx20">(C++20)</span></span></span></div></div></td></tr>
<tr class="t-nv"><td colspan="5"><div class="t-nv-ln-table"><div><a href="atomic/notify_one.html" title="cpp/atomic/atomic/notify one"><span class="t-lines"><span>atomic::notify_one</span></span></a></div><div><span class="t-lines"><span><span class="t-mark-rev t-since-cxx20">(C++20)</span></span></span></div></div></td></tr>
<tr class="t-nv"><td colspan="5"><div class="t-nv-ln-table"><div><a href="atomic/notify_all.html" title="cpp/atomic/atomic/notify all"><span class="t-lines"><span>atomic::notify_all</span></span></a></div><div><span class="t-lines"><span><span class="t-mark-rev t-since-cxx20">(C++20)</span></span></span></div></div></td></tr>
<tr class="t-nv-h1"><td colspan="5"> 常量</td></tr>
<tr class="t-nv"><td colspan="5"><div class="t-nv-ln-table"><div><a href="atomic/is_always_lock_free.html" title="cpp/atomic/atomic/is always lock free"><span class="t-lines"><span>atomic::is_always_lock_free</span></span></a></div><div><span class="t-lines"><span><span class="t-mark-rev t-since-cxx17">(C++17)</span></span></span></div></div></td></tr>
<tr class="t-nv-h1"><td colspan="5"> 特化的成员函数</td></tr>
<tr class="t-nv"><td colspan="5"><div class="t-nv-ln-table"><div><a href="atomic/fetch_add.html" title="cpp/atomic/atomic/fetch add"><span class="t-lines"><span>atomic::fetch_add</span></span></a></div></div></td></tr>
<tr class="t-nv"><td colspan="5"><div class="t-nv-ln-table"><div><a href="atomic/fetch_sub.html" title="cpp/atomic/atomic/fetch sub"><span class="t-lines"><span>atomic::fetch_sub</span></span></a></div></div></td></tr>
<tr class="t-nv"><td colspan="5"><div class="t-nv-ln-table"><div><a href="atomic/fetch_and.html" title="cpp/atomic/atomic/fetch and"><span class="t-lines"><span>atomic::fetch_and</span></span></a></div></div></td></tr>
<tr class="t-nv"><td colspan="5"><div class="t-nv-ln-table"><div><a href="atomic/fetch_or.html" title="cpp/atomic/atomic/fetch or"><span class="t-lines"><span>atomic::fetch_or</span></span></a></div></div></td></tr>
<tr class="t-nv"><td colspan="5"><div class="t-nv-ln-table"><div><a href="atomic/fetch_xor.html" title="cpp/atomic/atomic/fetch xor"><span class="t-lines"><span>atomic::fetch_xor</span></span></a></div></div></td></tr>
<tr class="t-nv"><td colspan="5"><div class="t-nv-ln-table"><div><a href="atomic/operator_arith.html" title="cpp/atomic/atomic/operator arith"><span class="t-lines"><span>atomic::operator++</span><span>atomic::operator++(int)</span><span>atomic::operator--</span><span>atomic::operator--(int)</span></span></a></div></div></td></tr>
<tr class="t-nv"><td colspan="5"><div class="t-nv-ln-table"><div><a href="atomic/operator_arith2.html" title="cpp/atomic/atomic/operator arith2"><span class="t-lines"><span>atomic::operator+=</span><span>atomic::operator-=</span><span>atomic::operator&amp;=</span><span>atomic::operator|=</span><span>atomic::operator^=</span></span></a></div></div></td></tr>
</table></div><div></div></div></div></div><div class="t-navbar-sep"> </div></div>
<table class="t-dcl-begin"><tbody>
<tr class="t-dsc-header">
<td> <div>定义于头文件 <code><a href="../header/atomic.html" title="cpp/header/atomic">&lt;atomic&gt;</a></code>
 </div></td>
<td></td>
<td></td>
</tr>
<tr class="t-dcl t-since-cxx11">
<td> <div><span class="mw-geshi cpp source-cpp"><span class="kw1">template</span><span class="sy1">&lt;</span> <span class="kw1">class</span> T <span class="sy1">&gt;</span><br>
<span class="kw1">struct</span> atomic<span class="sy4">;</span></span></div></td>
<td> (1) </td>
<td> <span class="t-mark-rev t-since-cxx11">(C++11 起)</span> </td>
</tr>
<tr class="t-dcl t-since-cxx11">
<td> <div><span class="mw-geshi cpp source-cpp"><span class="kw1">template</span><span class="sy1">&lt;</span> <span class="kw1">class</span> U <span class="sy1">&gt;</span><br>
<span class="kw1">struct</span> atomic<span class="sy1">&lt;</span>U<span class="sy2">*</span><span class="sy1">&gt;</span><span class="sy4">;</span></span></div></td>
<td> (2) </td>
<td> <span class="t-mark-rev t-since-cxx11">(C++11 起)</span> </td>
</tr>
<tr class="t-dsc-header">
<td> <div>定义于头文件 <code><a href="../header/memory.html" title="cpp/header/memory">&lt;memory&gt;</a></code>
 </div></td>
<td></td>
<td></td>
</tr>
<tr class="t-dcl t-since-cxx20">
<td> <div><span class="mw-geshi cpp source-cpp"><span class="kw1">template</span><span class="sy1">&lt;</span><span class="kw1">class</span> U<span class="sy1">&gt;</span><br>
<span class="kw1">struct</span> atomic<span class="sy1">&lt;</span><a href="../memory/shared_ptr.html"><span class="kw734">std::<span class="me2">shared_ptr</span></span></a><span class="sy1">&lt;</span>U<span class="sy1">&gt;&gt;</span><span class="sy4">;</span></span></div></td>
<td> (3) </td>
<td> <span class="t-mark-rev t-since-cxx20">(C++20 起)</span> </td>
</tr>
<tr class="t-dcl t-since-cxx20">
<td> <div><span class="mw-geshi cpp source-cpp"><span class="kw1">template</span><span class="sy1">&lt;</span><span class="kw1">class</span> U<span class="sy1">&gt;</span><br>
<span class="kw1">struct</span> atomic<span class="sy1">&lt;</span><a href="../memory/weak_ptr.html"><span class="kw741">std::<span class="me2">weak_ptr</span></span></a><span class="sy1">&lt;</span>U<span class="sy1">&gt;&gt;</span><span class="sy4">;</span></span></div></td>
<td> (4) </td>
<td> <span class="t-mark-rev t-since-cxx20">(C++20 起)</span> </td>
</tr>
<tr class="t-dcl-sep"><td></td><td></td><td></td></tr>
</tbody></table>
<p>每个 <code>std::atomic</code> 模板的实例化和全特化定义一个原子类型。若一个线程写入原子对象，同时另一线程从它读取，则行为良好定义（数据竞争的细节见<a href="../language/memory_model.html" title="cpp/language/memory model">内存模型</a>）。
</p><p>另外，对原子对象的访问可以建立线程间同步，并按 <span class="t-lc"><a href="memory_order.html" title="cpp/atomic/memory order">std::memory_order</a></span> 所对非原子内存访问定序。
</p><p><code>std::atomic</code> 既不可复制亦不可移动。
</p>
<h3><span class="mw-headline" id=".E7.89.B9.E5.8C.96">特化</span></h3>
<h4><span class="mw-headline" id=".E5.88.9D.E7.AD.89.E6.A8.A1.E6.9D.BF">初等模板</span></h4>
<p>初等 <code>std::atomic</code> 模板可用任何满足<a href="../named_req/CopyConstructible.html" title="cpp/named req/CopyConstructible"><i>可复制构造</i> <span style="font-family: Georgia, 'DejaVu Serif', serif; font-style:italic">(CopyConstructible)</span> </a>及<a href="../named_req/CopyAssignable.html" title="cpp/named req/CopyAssignable"><i>可复制赋值</i> <span style="font-family: Georgia, 'DejaVu Serif', serif; font-style:italic">(CopyAssignable)</span> </a>的<a href="../named_req/TriviallyCopyable.html" title="cpp/named req/TriviallyCopyable"><i>可平凡复制</i> <span style="font-family: Georgia, 'DejaVu Serif', serif; font-style:italic">(TriviallyCopyable)</span> </a> 类型 <code>T</code> 特化。若下列任何值为 <code>false</code> 则程序为谬构：
</p>
<ul><li> <span class="t-c"><span class="mw-geshi cpp source-cpp"><a href="../types/is_trivially_copyable.html"><span class="kw500">std::<span class="me2">is_trivially_copyable</span></span></a><span class="sy1">&lt;</span>T<span class="sy1">&gt;</span><span class="sy4">::</span><span class="me2">value</span></span></span>
</li><li> <span class="t-c"><span class="mw-geshi cpp source-cpp"><a href="../types/is_copy_constructible.html"><span class="kw532">std::<span class="me2">is_copy_constructible</span></span></a><span class="sy1">&lt;</span>T<span class="sy1">&gt;</span><span class="sy4">::</span><span class="me2">value</span></span></span>
</li><li> <span class="t-c"><span class="mw-geshi cpp source-cpp"><a href="../types/is_move_constructible.html"><span class="kw538">std::<span class="me2">is_move_constructible</span></span></a><span class="sy1">&lt;</span>T<span class="sy1">&gt;</span><span class="sy4">::</span><span class="me2">value</span></span></span>
</li><li> <span class="t-c"><span class="mw-geshi cpp source-cpp"><a href="../types/is_copy_assignable.html"><span class="kw550">std::<span class="me2">is_copy_assignable</span></span></a><span class="sy1">&lt;</span>T<span class="sy1">&gt;</span><span class="sy4">::</span><span class="me2">value</span></span></span>
</li><li> <span class="t-c"><span class="mw-geshi cpp source-cpp"><a href="../types/is_move_assignable.html"><span class="kw556">std::<span class="me2">is_move_assignable</span></span></a><span class="sy1">&lt;</span>T<span class="sy1">&gt;</span><span class="sy4">::</span><span class="me2">value</span></span></span>
</li></ul>
<p><span class="t-c"><span class="mw-geshi cpp source-cpp">std<span class="sy4">::</span><span class="me2">atomic</span><span class="sy1">&lt;</span><span class="kw4">bool</span><span class="sy1">&gt;</span></span></span> 使用初等模板。它保证是标准布局结构体。
</p>
<h4><span class="mw-headline" id=".E9.83.A8.E5.88.86.E7.89.B9.E5.8C.96">部分特化</span></h4>
<p>标准库为下列类型提供 <code>std::atomic</code> 模板的特化，它们拥有初等模板所不拥有的额外属性：
</p><p>2) 对所有指针类型的部分特化 <span class="t-c"><span class="mw-geshi cpp source-cpp">std<span class="sy4">::</span><span class="me2">atomic</span><span class="sy1">&lt;</span>U<span class="sy2">*</span><span class="sy1">&gt;</span></span></span> 。这些特化拥有标准布局<span class="t-rev-inl t-until-cxx20"><span>、平凡默认构造函数</span> <span><span class="t-mark-rev t-until-cxx20">(C++20 前)</span></span></span>和平凡析构函数。除了为所有原子类型提供的操作，这些特化额外支持适合指针类型的原子算术运算，例如 <a href="atomic/fetch_add.html" title="cpp/atomic/atomic/fetch add"><code>fetch_add</code></a> 、 <a href="atomic/fetch_sub.html" title="cpp/atomic/atomic/fetch sub"><code>fetch_sub</code></a> 。
</p>
 <table class="t-rev-begin">
<tr class="t-rev t-since-cxx20"><td>
<p>3-4) 为 <span class="t-lc"><a href="../memory/shared_ptr.html" title="cpp/memory/shared ptr">std::shared_ptr</a></span> 和 <span class="t-lc"><a href="../memory/weak_ptr.html" title="cpp/memory/weak ptr">std::weak_ptr</a></span> 提供部分特化 <span class="t-c"><span class="mw-geshi cpp source-cpp">std<span class="sy4">::</span><span class="me2">atomic</span><span class="sy1">&lt;</span><a href="../memory/shared_ptr.html"><span class="kw734">std::<span class="me2">shared_ptr</span></span></a><span class="sy1">&lt;</span>U<span class="sy1">&gt;&gt;</span></span></span> 和 <span class="t-c"><span class="mw-geshi cpp source-cpp">std<span class="sy4">::</span><span class="me2">atomic</span><span class="sy1">&lt;</span><a href="../memory/weak_ptr.html"><span class="kw741">std::<span class="me2">weak_ptr</span></span></a><span class="sy1">&lt;</span>U<span class="sy1">&gt;&gt;</span></span></span> 。
</p><p>细节见 <a href="../memory/shared_ptr/atomic2.html" title="cpp/memory/shared ptr/atomic2"><tt>std::atomic<span class="t-dsc-small">&lt;std::shared_ptr&gt;</span></tt></a> 和 <a href="../memory/weak_ptr/atomic2.html" title="cpp/memory/weak ptr/atomic2"><tt>std::atomic<span class="t-dsc-small">&lt;std::weak_ptr&gt;</span></tt></a> 。
</p>
</td>
<td><span class="t-mark-rev t-since-cxx20">(C++20 起)</span></td></tr>
</table>
<h4><span class="mw-headline" id=".E5.AF.B9.E6.95.B4.E6.95.B0.E7.B1.BB.E5.9E.8B.E7.9A.84.E7.89.B9.E5.8C.96"> 对整数类型的特化 </span></h4>
<p>以下列整数类型之一实例化时， <code>std::atomic</code> 提供适合于整数类型的额外原子操作，例如 <a href="atomic/fetch_add.html" title="cpp/atomic/atomic/fetch add"><code>fetch_add</code></a> 、 <a href="atomic/fetch_sub.html" title="cpp/atomic/atomic/fetch sub"><code>fetch_sub</code></a> 、 <a href="atomic/fetch_and.html" title="cpp/atomic/atomic/fetch and"><code>fetch_and</code></a> 、 <a href="atomic/fetch_or.html" title="cpp/atomic/atomic/fetch or"><code>fetch_or</code></a> 、 <a href="atomic/fetch_xor.html" title="cpp/atomic/atomic/fetch xor"><code>fetch_xor</code></a> ：
</p>
<dl><dd><ul><li> 字符类型 <span class="t-c"><span class="mw-geshi cpp source-cpp"><span class="kw4">char</span></span></span> <span class="t-rev-inl t-since-cxx20"><span>、 <span class="t-c"><span class="mw-geshi cpp source-cpp">char8_t</span></span> </span> <span><span class="t-mark-rev t-since-cxx20">(C++20 起)</span></span></span>、 <span class="t-c"><span class="mw-geshi cpp source-cpp"><span class="kw4">char16_t</span></span></span> 、 <span class="t-c"><span class="mw-geshi cpp source-cpp"><span class="kw4">char32_t</span></span></span> 和 <span class="t-c"><span class="mw-geshi cpp source-cpp"><span class="kw4">wchar_t</span></span></span> ；
</li><li> 标准有符号整数类型： <span class="t-c"><span class="mw-geshi cpp source-cpp"><span class="kw4">signed</span> <span class="kw4">char</span></span></span> 、 <span class="t-c"><span class="mw-geshi cpp source-cpp"><span class="kw4">short</span></span></span> 、 <span class="t-c"><span class="mw-geshi cpp source-cpp"><span class="kw4">int</span></span></span> 、 <span class="t-c"><span class="mw-geshi cpp source-cpp"><span class="kw4">long</span></span></span> 和 <span class="t-c"><span class="mw-geshi cpp source-cpp"><span class="kw4">long</span> <span class="kw4">long</span></span></span> ；
</li><li> 标准无符号整数类型： <span class="t-c"><span class="mw-geshi cpp source-cpp"><span class="kw4">unsigned</span> <span class="kw4">char</span></span></span> 、 <span class="t-c"><span class="mw-geshi cpp source-cpp"><span class="kw4">unsigned</span> <span class="kw4">short</span></span></span> 、 <span class="t-c"><span class="mw-geshi cpp source-cpp"><span class="kw4">unsigned</span> <span class="kw4">int</span></span></span> 、 <span class="t-c"><span class="mw-geshi cpp source-cpp"><span class="kw4">unsigned</span> <span class="kw4">long</span></span></span> 和 <span class="t-c"><span class="mw-geshi cpp source-cpp"><span class="kw4">unsigned</span> <span class="kw4">long</span> <span class="kw4">long</span></span></span> ；
</li><li> 任何头文件 <a href="../header/cstdint.html" title="cpp/header/cstdint"><tt>&lt;cstdint&gt;</tt></a> 中的 typedef 所需的额外整数类型。
</li></ul>
</dd></dl>
<p>另外，结果的 <code>std::atomic&lt;<i>Integral</i>&gt;</code> 特化拥有标准布局<span class="t-rev-inl t-until-cxx20"><span>、平凡默认构造函数</span> <span><span class="t-mark-rev t-until-cxx20">(C++20 前)</span></span></span>和平凡析构函数。定义有符号整数算术为使用补码；无未定义结果。
</p>
 <table class="t-rev-begin">
<tr class="t-rev t-since-cxx20"><td>
<h4> <span class="mw-headline" id=".E5.AF.B9.E6.B5.AE.E7.82.B9.E7.B1.BB.E5.9E.8B.E7.9A.84.E7.89.B9.E5.8C.96">对浮点类型的特化</span></h4>
<p>以浮点类型 <span class="t-c"><span class="mw-geshi cpp source-cpp"><span class="kw4">float</span></span></span> 、 <span class="t-c"><span class="mw-geshi cpp source-cpp"><span class="kw4">double</span></span></span> 和 <span class="t-c"><span class="mw-geshi cpp source-cpp"><span class="kw4">long</span> <span class="kw4">double</span></span></span> 之一实例化时， <code>std::atomic</code> 提供适合于浮点类型的额外原子操作，例如 <a href="atomic/fetch_add.html" title="cpp/atomic/atomic/fetch add"><code>fetch_add</code></a> 和 <a href="atomic/fetch_sub.html" title="cpp/atomic/atomic/fetch sub"><code>fetch_sub</code></a> 。
</p><p>另外，结果的 <code>std::atomic&lt;<i>Floating</i>&gt;</code> 特化拥有标准布局和平凡析构函数。
</p><p>无操作导致未定义行为，即使结果不能以浮点类型表示。有效的<a href="../numeric/fenv.html" title="cpp/numeric/fenv">浮点环境</a>可能不同于调用方线程的浮点环境。
</p>
</td>
<td><span class="t-mark-rev t-since-cxx20">(C++20 起)</span></td></tr>
</table>
<h3><span class="mw-headline" id=".E7.B1.BB.E5.9E.8B.E5.88.AB.E5.90.8D">类型别名</span></h3>
<p>为 <span class="t-c"><span class="mw-geshi cpp source-cpp"><span class="kw4">bool</span></span></span> 和所有上面列出的整数类型提供如下类型别名：
</p>
<table class="t-dsc-begin">

<tr class="t-dsc-sep">
<td colspan="2">  
</td></tr>
<tr class="t-dsc-hitem">
<td> 类型别名
</td>
<td> 定义
</td></tr>


<tr class="t-dsc">
<td>  <span class="t-c"><span class="mw-geshi cpp source-cpp">std<span class="sy4">::</span><span class="me2">atomic_bool</span></span></span>
</td>
<td>  <span class="t-c"><span class="mw-geshi cpp source-cpp">std<span class="sy4">::</span><span class="me2">atomic</span><span class="sy1">&lt;</span><span class="kw4">bool</span><span class="sy1">&gt;</span></span></span>
</td></tr>

<tr class="t-dsc">
<td>  <span class="t-c"><span class="mw-geshi cpp source-cpp">std<span class="sy4">::</span><span class="me2">atomic_char</span></span></span>
</td>
<td>  <span class="t-c"><span class="mw-geshi cpp source-cpp">std<span class="sy4">::</span><span class="me2">atomic</span><span class="sy1">&lt;</span><span class="kw4">char</span><span class="sy1">&gt;</span></span></span>
</td></tr>

<tr class="t-dsc">
<td>  <span class="t-c"><span class="mw-geshi cpp source-cpp">std<span class="sy4">::</span><span class="me2">atomic_schar</span></span></span>
</td>
<td>  <span class="t-c"><span class="mw-geshi cpp source-cpp">std<span class="sy4">::</span><span class="me2">atomic</span><span class="sy1">&lt;</span><span class="kw4">signed</span> <span class="kw4">char</span><span class="sy1">&gt;</span></span></span>
</td></tr>

<tr class="t-dsc">
<td>  <span class="t-c"><span class="mw-geshi cpp source-cpp">std<span class="sy4">::</span><span class="me2">atomic_uchar</span></span></span>
</td>
<td>  <span class="t-c"><span class="mw-geshi cpp source-cpp">std<span class="sy4">::</span><span class="me2">atomic</span><span class="sy1">&lt;</span><span class="kw4">unsigned</span> <span class="kw4">char</span><span class="sy1">&gt;</span></span></span>
</td></tr>

<tr class="t-dsc">
<td>  <span class="t-c"><span class="mw-geshi cpp source-cpp">std<span class="sy4">::</span><span class="me2">atomic_short</span></span></span>
</td>
<td>  <span class="t-c"><span class="mw-geshi cpp source-cpp">std<span class="sy4">::</span><span class="me2">atomic</span><span class="sy1">&lt;</span><span class="kw4">short</span><span class="sy1">&gt;</span></span></span>
</td></tr>

<tr class="t-dsc">
<td>  <span class="t-c"><span class="mw-geshi cpp source-cpp">std<span class="sy4">::</span><span class="me2">atomic_ushort</span></span></span>
</td>
<td>  <span class="t-c"><span class="mw-geshi cpp source-cpp">std<span class="sy4">::</span><span class="me2">atomic</span><span class="sy1">&lt;</span><span class="kw4">unsigned</span> <span class="kw4">short</span><span class="sy1">&gt;</span></span></span>
</td></tr>

<tr class="t-dsc">
<td>  <span class="t-c"><span class="mw-geshi cpp source-cpp">std<span class="sy4">::</span><span class="me2">atomic_int</span></span></span>
</td>
<td>  <span class="t-c"><span class="mw-geshi cpp source-cpp">std<span class="sy4">::</span><span class="me2">atomic</span><span class="sy1">&lt;</span><span class="kw4">int</span><span class="sy1">&gt;</span></span></span>
</td></tr>

<tr class="t-dsc">
<td>  <span class="t-c"><span class="mw-geshi cpp source-cpp">std<span class="sy4">::</span><span class="me2">atomic_uint</span></span></span>
</td>
<td>  <span class="t-c"><span class="mw-geshi cpp source-cpp">std<span class="sy4">::</span><span class="me2">atomic</span><span class="sy1">&lt;</span><span class="kw4">unsigned</span> <span class="kw4">int</span><span class="sy1">&gt;</span></span></span>
</td></tr>

<tr class="t-dsc">
<td>  <span class="t-c"><span class="mw-geshi cpp source-cpp">std<span class="sy4">::</span><span class="me2">atomic_long</span></span></span>
</td>
<td>  <span class="t-c"><span class="mw-geshi cpp source-cpp">std<span class="sy4">::</span><span class="me2">atomic</span><span class="sy1">&lt;</span><span class="kw4">long</span><span class="sy1">&gt;</span></span></span>
</td></tr>

<tr class="t-dsc">
<td>  <span class="t-c"><span class="mw-geshi cpp source-cpp">std<span class="sy4">::</span><span class="me2">atomic_ulong</span></span></span>
</td>
<td>  <span class="t-c"><span class="mw-geshi cpp source-cpp">std<span class="sy4">::</span><span class="me2">atomic</span><span class="sy1">&lt;</span><span class="kw4">unsigned</span> <span class="kw4">long</span><span class="sy1">&gt;</span></span></span>
</td></tr>

<tr class="t-dsc">
<td>  <span class="t-c"><span class="mw-geshi cpp source-cpp">std<span class="sy4">::</span><span class="me2">atomic_llong</span></span></span>
</td>
<td>  <span class="t-c"><span class="mw-geshi cpp source-cpp">std<span class="sy4">::</span><span class="me2">atomic</span><span class="sy1">&lt;</span><span class="kw4">long</span> <span class="kw4">long</span><span class="sy1">&gt;</span></span></span>
</td></tr>

<tr class="t-dsc">
<td>  <span class="t-c"><span class="mw-geshi cpp source-cpp">std<span class="sy4">::</span><span class="me2">atomic_ullong</span></span></span>
</td>
<td>  <span class="t-c"><span class="mw-geshi cpp source-cpp">std<span class="sy4">::</span><span class="me2">atomic</span><span class="sy1">&lt;</span><span class="kw4">unsigned</span> <span class="kw4">long</span> <span class="kw4">long</span><span class="sy1">&gt;</span></span></span>
</td></tr>

<tr class="t-dsc">
<td>  <span class="t-c"><span class="mw-geshi cpp source-cpp">std<span class="sy4">::</span><span class="me2">atomic_char8_t</span></span></span> <span class="t-mark-rev t-since-cxx20">(C++20)</span>
</td>
<td>  <span class="t-c"><span class="mw-geshi cpp source-cpp">std<span class="sy4">::</span><span class="me2">atomic</span><span class="sy1">&lt;</span>char8_t<span class="sy1">&gt;</span></span></span>
</td></tr>

<tr class="t-dsc">
<td>  <span class="t-c"><span class="mw-geshi cpp source-cpp">std<span class="sy4">::</span><span class="me2">atomic_char16_t</span></span></span>
</td>
<td>  <span class="t-c"><span class="mw-geshi cpp source-cpp">std<span class="sy4">::</span><span class="me2">atomic</span><span class="sy1">&lt;</span><span class="kw4">char16_t</span><span class="sy1">&gt;</span></span></span>
</td></tr>

<tr class="t-dsc">
<td>  <span class="t-c"><span class="mw-geshi cpp source-cpp">std<span class="sy4">::</span><span class="me2">atomic_char32_t</span></span></span>
</td>
<td>  <span class="t-c"><span class="mw-geshi cpp source-cpp">std<span class="sy4">::</span><span class="me2">atomic</span><span class="sy1">&lt;</span><span class="kw4">char32_t</span><span class="sy1">&gt;</span></span></span>
</td></tr>

<tr class="t-dsc">
<td>  <span class="t-c"><span class="mw-geshi cpp source-cpp">std<span class="sy4">::</span><span class="me2">atomic_wchar_t</span></span></span>
</td>
<td>  <span class="t-c"><span class="mw-geshi cpp source-cpp">std<span class="sy4">::</span><span class="me2">atomic</span><span class="sy1">&lt;</span><span class="kw4">wchar_t</span><span class="sy1">&gt;</span></span></span>
</td></tr>

<tr class="t-dsc">
<td>  <span class="t-c"><span class="mw-geshi cpp source-cpp">std<span class="sy4">::</span><span class="me2">atomic_int8_t</span></span></span>
</td>
<td>  <span class="t-c"><span class="mw-geshi cpp source-cpp">std<span class="sy4">::</span><span class="me2">atomic</span><span class="sy1">&lt;</span><a href="../types/integer.html"><span class="kw106">std::<span class="me2">int8_t</span></span></a><span class="sy1">&gt;</span></span></span>
</td></tr>

<tr class="t-dsc">
<td>  <span class="t-c"><span class="mw-geshi cpp source-cpp">std<span class="sy4">::</span><span class="me2">atomic_uint8_t</span></span></span>
</td>
<td>  <span class="t-c"><span class="mw-geshi cpp source-cpp">std<span class="sy4">::</span><span class="me2">atomic</span><span class="sy1">&lt;</span><a href="../types/integer.html"><span class="kw120">std::<span class="me2">uint8_t</span></span></a><span class="sy1">&gt;</span></span></span>
</td></tr>

<tr class="t-dsc">
<td>  <span class="t-c"><span class="mw-geshi cpp source-cpp">std<span class="sy4">::</span><span class="me2">atomic_int16_t</span></span></span>
</td>
<td>  <span class="t-c"><span class="mw-geshi cpp source-cpp">std<span class="sy4">::</span><span class="me2">atomic</span><span class="sy1">&lt;</span><a href="../types/integer.html"><span class="kw107">std::<span class="me2">int16_t</span></span></a><span class="sy1">&gt;</span></span></span>
</td></tr>

<tr class="t-dsc">
<td>  <span class="t-c"><span class="mw-geshi cpp source-cpp">std<span class="sy4">::</span><span class="me2">atomic_uint16_t</span></span></span>
</td>
<td>  <span class="t-c"><span class="mw-geshi cpp source-cpp">std<span class="sy4">::</span><span class="me2">atomic</span><span class="sy1">&lt;</span><a href="../types/integer.html"><span class="kw121">std::<span class="me2">uint16_t</span></span></a><span class="sy1">&gt;</span></span></span>
</td></tr>

<tr class="t-dsc">
<td>  <span class="t-c"><span class="mw-geshi cpp source-cpp">std<span class="sy4">::</span><span class="me2">atomic_int32_t</span></span></span>
</td>
<td>  <span class="t-c"><span class="mw-geshi cpp source-cpp">std<span class="sy4">::</span><span class="me2">atomic</span><span class="sy1">&lt;</span><a href="../types/integer.html"><span class="kw108">std::<span class="me2">int32_t</span></span></a><span class="sy1">&gt;</span></span></span>
</td></tr>

<tr class="t-dsc">
<td>  <span class="t-c"><span class="mw-geshi cpp source-cpp">std<span class="sy4">::</span><span class="me2">atomic_uint32_t</span></span></span>
</td>
<td>  <span class="t-c"><span class="mw-geshi cpp source-cpp">std<span class="sy4">::</span><span class="me2">atomic</span><span class="sy1">&lt;</span><a href="../types/integer.html"><span class="kw122">std::<span class="me2">uint32_t</span></span></a><span class="sy1">&gt;</span></span></span>
</td></tr>

<tr class="t-dsc">
<td>  <span class="t-c"><span class="mw-geshi cpp source-cpp">std<span class="sy4">::</span><span class="me2">atomic_int64_t</span></span></span>
</td>
<td>  <span class="t-c"><span class="mw-geshi cpp source-cpp">std<span class="sy4">::</span><span class="me2">atomic</span><span class="sy1">&lt;</span><a href="../types/integer.html"><span class="kw109">std::<span class="me2">int64_t</span></span></a><span class="sy1">&gt;</span></span></span>
</td></tr>

<tr class="t-dsc">
<td>  <span class="t-c"><span class="mw-geshi cpp source-cpp">std<span class="sy4">::</span><span class="me2">atomic_uint64_t</span></span></span>
</td>
<td>  <span class="t-c"><span class="mw-geshi cpp source-cpp">std<span class="sy4">::</span><span class="me2">atomic</span><span class="sy1">&lt;</span><a href="../types/integer.html"><span class="kw123">std::<span class="me2">uint64_t</span></span></a><span class="sy1">&gt;</span></span></span>
</td></tr>

<tr class="t-dsc">
<td>  <span class="t-c"><span class="mw-geshi cpp source-cpp">std<span class="sy4">::</span><span class="me2">atomic_int_least8_t</span></span></span>
</td>
<td>  <span class="t-c"><span class="mw-geshi cpp source-cpp">std<span class="sy4">::</span><span class="me2">atomic</span><span class="sy1">&lt;</span><a href="../types/integer.html"><span class="kw114">std::<span class="me2">int_least8_t</span></span></a><span class="sy1">&gt;</span></span></span>
</td></tr>

<tr class="t-dsc">
<td>  <span class="t-c"><span class="mw-geshi cpp source-cpp">std<span class="sy4">::</span><span class="me2">atomic_uint_least8_t</span></span></span>
</td>
<td>  <span class="t-c"><span class="mw-geshi cpp source-cpp">std<span class="sy4">::</span><span class="me2">atomic</span><span class="sy1">&lt;</span><a href="../types/integer.html"><span class="kw128">std::<span class="me2">uint_least8_t</span></span></a><span class="sy1">&gt;</span></span></span>
</td></tr>

<tr class="t-dsc">
<td>  <span class="t-c"><span class="mw-geshi cpp source-cpp">std<span class="sy4">::</span><span class="me2">atomic_int_least16_t</span></span></span>
</td>
<td>  <span class="t-c"><span class="mw-geshi cpp source-cpp">std<span class="sy4">::</span><span class="me2">atomic</span><span class="sy1">&lt;</span><a href="../types/integer.html"><span class="kw115">std::<span class="me2">int_least16_t</span></span></a><span class="sy1">&gt;</span></span></span>
</td></tr>

<tr class="t-dsc">
<td>  <span class="t-c"><span class="mw-geshi cpp source-cpp">std<span class="sy4">::</span><span class="me2">atomic_uint_least16_t</span></span></span>
</td>
<td>  <span class="t-c"><span class="mw-geshi cpp source-cpp">std<span class="sy4">::</span><span class="me2">atomic</span><span class="sy1">&lt;</span><a href="../types/integer.html"><span class="kw129">std::<span class="me2">uint_least16_t</span></span></a><span class="sy1">&gt;</span></span></span>
</td></tr>

<tr class="t-dsc">
<td>  <span class="t-c"><span class="mw-geshi cpp source-cpp">std<span class="sy4">::</span><span class="me2">atomic_int_least32_t</span></span></span>
</td>
<td>  <span class="t-c"><span class="mw-geshi cpp source-cpp">std<span class="sy4">::</span><span class="me2">atomic</span><span class="sy1">&lt;</span><a href="../types/integer.html"><span class="kw116">std::<span class="me2">int_least32_t</span></span></a><span class="sy1">&gt;</span></span></span>
</td></tr>

<tr class="t-dsc">
<td>  <span class="t-c"><span class="mw-geshi cpp source-cpp">std<span class="sy4">::</span><span class="me2">atomic_uint_least32_t</span></span></span>
</td>
<td>  <span class="t-c"><span class="mw-geshi cpp source-cpp">std<span class="sy4">::</span><span class="me2">atomic</span><span class="sy1">&lt;</span><a href="../types/integer.html"><span class="kw130">std::<span class="me2">uint_least32_t</span></span></a><span class="sy1">&gt;</span></span></span>
</td></tr>

<tr class="t-dsc">
<td>  <span class="t-c"><span class="mw-geshi cpp source-cpp">std<span class="sy4">::</span><span class="me2">atomic_int_least64_t</span></span></span>
</td>
<td>  <span class="t-c"><span class="mw-geshi cpp source-cpp">std<span class="sy4">::</span><span class="me2">atomic</span><span class="sy1">&lt;</span><a href="../types/integer.html"><span class="kw117">std::<span class="me2">int_least64_t</span></span></a><span class="sy1">&gt;</span></span></span>
</td></tr>

<tr class="t-dsc">
<td>  <span class="t-c"><span class="mw-geshi cpp source-cpp">std<span class="sy4">::</span><span class="me2">atomic_uint_least64_t</span></span></span>
</td>
<td>  <span class="t-c"><span class="mw-geshi cpp source-cpp">std<span class="sy4">::</span><span class="me2">atomic</span><span class="sy1">&lt;</span><a href="../types/integer.html"><span class="kw131">std::<span class="me2">uint_least64_t</span></span></a><span class="sy1">&gt;</span></span></span>
</td></tr>

<tr class="t-dsc">
<td>  <span class="t-c"><span class="mw-geshi cpp source-cpp">std<span class="sy4">::</span><span class="me2">atomic_int_fast8_t</span></span></span>
</td>
<td>  <span class="t-c"><span class="mw-geshi cpp source-cpp">std<span class="sy4">::</span><span class="me2">atomic</span><span class="sy1">&lt;</span><a href="../types/integer.html"><span class="kw110">std::<span class="me2">int_fast8_t</span></span></a><span class="sy1">&gt;</span></span></span>
</td></tr>

<tr class="t-dsc">
<td>  <span class="t-c"><span class="mw-geshi cpp source-cpp">std<span class="sy4">::</span><span class="me2">atomic_uint_fast8_t</span></span></span>
</td>
<td>  <span class="t-c"><span class="mw-geshi cpp source-cpp">std<span class="sy4">::</span><span class="me2">atomic</span><span class="sy1">&lt;</span><a href="../types/integer.html"><span class="kw124">std::<span class="me2">uint_fast8_t</span></span></a><span class="sy1">&gt;</span></span></span>
</td></tr>

<tr class="t-dsc">
<td>  <span class="t-c"><span class="mw-geshi cpp source-cpp">std<span class="sy4">::</span><span class="me2">atomic_int_fast16_t</span></span></span>
</td>
<td>  <span class="t-c"><span class="mw-geshi cpp source-cpp">std<span class="sy4">::</span><span class="me2">atomic</span><span class="sy1">&lt;</span><a href="../types/integer.html"><span class="kw111">std::<span class="me2">int_fast16_t</span></span></a><span class="sy1">&gt;</span></span></span>
</td></tr>

<tr class="t-dsc">
<td>  <span class="t-c"><span class="mw-geshi cpp source-cpp">std<span class="sy4">::</span><span class="me2">atomic_uint_fast16_t</span></span></span>
</td>
<td>  <span class="t-c"><span class="mw-geshi cpp source-cpp">std<span class="sy4">::</span><span class="me2">atomic</span><span class="sy1">&lt;</span><a href="../types/integer.html"><span class="kw125">std::<span class="me2">uint_fast16_t</span></span></a><span class="sy1">&gt;</span></span></span>
</td></tr>

<tr class="t-dsc">
<td>  <span class="t-c"><span class="mw-geshi cpp source-cpp">std<span class="sy4">::</span><span class="me2">atomic_int_fast32_t</span></span></span>
</td>
<td>  <span class="t-c"><span class="mw-geshi cpp source-cpp">std<span class="sy4">::</span><span class="me2">atomic</span><span class="sy1">&lt;</span><a href="../types/integer.html"><span class="kw112">std::<span class="me2">int_fast32_t</span></span></a><span class="sy1">&gt;</span></span></span>
</td></tr>

<tr class="t-dsc">
<td>  <span class="t-c"><span class="mw-geshi cpp source-cpp">std<span class="sy4">::</span><span class="me2">atomic_uint_fast32_t</span></span></span>
</td>
<td>  <span class="t-c"><span class="mw-geshi cpp source-cpp">std<span class="sy4">::</span><span class="me2">atomic</span><span class="sy1">&lt;</span><a href="../types/integer.html"><span class="kw126">std::<span class="me2">uint_fast32_t</span></span></a><span class="sy1">&gt;</span></span></span>
</td></tr>

<tr class="t-dsc">
<td>  <span class="t-c"><span class="mw-geshi cpp source-cpp">std<span class="sy4">::</span><span class="me2">atomic_int_fast64_t</span></span></span>
</td>
<td>  <span class="t-c"><span class="mw-geshi cpp source-cpp">std<span class="sy4">::</span><span class="me2">atomic</span><span class="sy1">&lt;</span><a href="../types/integer.html"><span class="kw113">std::<span class="me2">int_fast64_t</span></span></a><span class="sy1">&gt;</span></span></span>
</td></tr>

<tr class="t-dsc">
<td>  <span class="t-c"><span class="mw-geshi cpp source-cpp">std<span class="sy4">::</span><span class="me2">atomic_uint_fast64_t</span></span></span>
</td>
<td>  <span class="t-c"><span class="mw-geshi cpp source-cpp">std<span class="sy4">::</span><span class="me2">atomic</span><span class="sy1">&lt;</span><a href="../types/integer.html"><span class="kw127">std::<span class="me2">uint_fast64_t</span></span></a><span class="sy1">&gt;</span></span></span>
</td></tr>

<tr class="t-dsc">
<td>  <span class="t-c"><span class="mw-geshi cpp source-cpp">std<span class="sy4">::</span><span class="me2">atomic_intptr_t</span></span></span>
</td>
<td>  <span class="t-c"><span class="mw-geshi cpp source-cpp">std<span class="sy4">::</span><span class="me2">atomic</span><span class="sy1">&lt;</span><a href="../types/integer.html"><span class="kw119">std::<span class="me2">intptr_t</span></span></a><span class="sy1">&gt;</span></span></span>
</td></tr>

<tr class="t-dsc">
<td>  <span class="t-c"><span class="mw-geshi cpp source-cpp">std<span class="sy4">::</span><span class="me2">atomic_uintptr_t</span></span></span>
</td>
<td>  <span class="t-c"><span class="mw-geshi cpp source-cpp">std<span class="sy4">::</span><span class="me2">atomic</span><span class="sy1">&lt;</span><a href="../types/integer.html"><span class="kw133">std::<span class="me2">uintptr_t</span></span></a><span class="sy1">&gt;</span></span></span>
</td></tr>

<tr class="t-dsc">
<td>  <span class="t-c"><span class="mw-geshi cpp source-cpp">std<span class="sy4">::</span><span class="me2">atomic_size_t</span></span></span>
</td>
<td>  <span class="t-c"><span class="mw-geshi cpp source-cpp">std<span class="sy4">::</span><span class="me2">atomic</span><span class="sy1">&lt;</span><a href="../types/size_t.html"><span class="kw100">std::<span class="me2">size_t</span></span></a><span class="sy1">&gt;</span></span></span>
</td></tr>

<tr class="t-dsc">
<td>  <span class="t-c"><span class="mw-geshi cpp source-cpp">std<span class="sy4">::</span><span class="me2">atomic_ptrdiff_t</span></span></span>
</td>
<td>  <span class="t-c"><span class="mw-geshi cpp source-cpp">std<span class="sy4">::</span><span class="me2">atomic</span><span class="sy1">&lt;</span><a href="../types/ptrdiff_t.html"><span class="kw101">std::<span class="me2">ptrdiff_t</span></span></a><span class="sy1">&gt;</span></span></span>
</td></tr>

<tr class="t-dsc">
<td>  <span class="t-c"><span class="mw-geshi cpp source-cpp">std<span class="sy4">::</span><span class="me2">atomic_intmax_t</span></span></span>
</td>
<td>  <span class="t-c"><span class="mw-geshi cpp source-cpp">std<span class="sy4">::</span><span class="me2">atomic</span><span class="sy1">&lt;</span><a href="../types/integer.html"><span class="kw118">std::<span class="me2">intmax_t</span></span></a><span class="sy1">&gt;</span></span></span>
</td></tr>

<tr class="t-dsc">
<td>  <span class="t-c"><span class="mw-geshi cpp source-cpp">std<span class="sy4">::</span><span class="me2">atomic_uintmax_t</span></span></span>
</td>
<td>  <span class="t-c"><span class="mw-geshi cpp source-cpp">std<span class="sy4">::</span><span class="me2">atomic</span><span class="sy1">&lt;</span><a href="../types/integer.html"><span class="kw132">std::<span class="me2">uintmax_t</span></span></a><span class="sy1">&gt;</span></span></span>
</td></tr>
</table>
<p>注意： <code>std::atomic_int<i>N</i>_t</code> 、 <code>std::atomic_uint<i>N</i>_t</code> 、 <code>std::atomic_intptr_t</code> 及 <code>atomic_uintptr_t</code> 分别若且唯若定义了 <code>std::int<i>N</i>_t</code> 、 <code>std::uint<i>N</i>_t</code> 、 <code>std::intptr_t</code> 及 <code>std::uintptr_t</code> 才有定义。
</p>
 <table class="t-rev-begin">
<tr class="t-rev t-since-cxx20"><td>
<p>提供额外的特殊用途类型别名：
</p>
<table class="t-dsc-begin">

<tr class="t-dsc">
<td>  <span class="t-c"><span class="mw-geshi cpp source-cpp">std<span class="sy4">::</span><span class="me2">atomic_signed_lock_free</span></span></span>
</td>
<td> 免锁且对于等待/提醒最高效的有符号整数原子类型
</td></tr>

<tr class="t-dsc">
<td>  <span class="t-c"><span class="mw-geshi cpp source-cpp">std<span class="sy4">::</span><span class="me2">atomic_unsigned_lock_free</span></span></span>
</td>
<td> 免锁且对于等待/提醒最高效的无符号整数原子类型
</td></tr>
</table>
</td>
<td><span class="t-mark-rev t-since-cxx20">(C++20 起)</span></td></tr>
</table>
<h3><span class="mw-headline" id=".E6.88.90.E5.91.98.E7.B1.BB.E5.9E.8B">成员类型</span></h3>
<table class="t-dsc-begin">

<tr class="t-dsc-sep">
<td colspan="2">  
</td></tr>
<tr class="t-dsc-hitem">
<td> 成员类型
</td>
<td> 定义
</td></tr>


<tr class="t-dsc">
<td>  <code>value_type</code>
</td>
<td>  <code>T</code> <span class="t-mark">(无论是否特化)</span>
</td></tr>

<tr class="t-dsc">
<td>  <code>difference_type</code>
</td>
<td>  <code>value_type</code> <span class="t-mark">(仅对 <code>atomic&lt;<i>Integral</i>&gt;</code> <span class="t-rev-inl t-since-cxx20"><span>和 <code>atomic&lt;<i>Floating</i>&gt;</code></span> <span><span class="t-mark-rev t-since-cxx20">(C++20 起)</span></span></span> 特化)</span><br> <span class="t-lc"><a href="../types/ptrdiff_t.html" title="cpp/types/ptrdiff t">std::ptrdiff_t</a></span> <span class="t-mark">(仅对 <code>atomic&lt;U*&gt;</code> 特化)</span>
</td></tr>
</table>
<p><code>difference_type</code> 不在初等 <code>atomic</code> 模板中，或不在对 <span class="t-lc"><a href="../memory/shared_ptr.html" title="cpp/memory/shared ptr">std::shared_ptr</a></span> 和 <span class="t-lc"><a href="../memory/weak_ptr.html" title="cpp/memory/weak ptr">std::weak_ptr</a></span> 的部分特化中定义。
</p>
<h3><span class="mw-headline" id=".E6.88.90.E5.91.98.E5.87.BD.E6.95.B0">成员函数</span></h3>
<table class="t-dsc-begin">

<tr class="t-dsc">
<td>  <div class="t-dsc-member-div t-dsc-member-nobold-div"><div><a href="atomic/atomic.html" title="cpp/atomic/atomic/atomic"> <span class="t-lines"><span>(构造函数)</span></span></a></div></div>
</td>
<td>  构造原子对象 <br> <span class="t-mark">(公开成员函数)</span> </td></tr>

<tr class="t-dsc">
<td>  <div class="t-dsc-member-div"><div><a href="atomic/operator%3D.html" title="cpp/atomic/atomic/operator="> <span class="t-lines"><span>operator=</span></span></a></div></div>
</td>
<td>  存储值于原子对象 <br> <span class="t-mark">(公开成员函数)</span> </td></tr>

<tr class="t-dsc">
<td>  <div class="t-dsc-member-div"><div><a href="atomic/is_lock_free.html" title="cpp/atomic/atomic/is lock free"> <span class="t-lines"><span>is_lock_free</span></span></a></div></div>
</td>
<td>  检查原子对象是否免锁 <br> <span class="t-mark">(公开成员函数)</span> </td></tr>

<tr class="t-dsc">
<td>  <div class="t-dsc-member-div"><div><a href="atomic/store.html" title="cpp/atomic/atomic/store"> <span class="t-lines"><span>store</span></span></a></div></div>
</td>
<td>  原子地以非原子对象替换原子对象的值 <br> <span class="t-mark">(公开成员函数)</span> </td></tr>

<tr class="t-dsc">
<td>  <div class="t-dsc-member-div"><div><a href="atomic/load.html" title="cpp/atomic/atomic/load"> <span class="t-lines"><span>load</span></span></a></div></div>
</td>
<td>  原子地获得原子对象的值 <br> <span class="t-mark">(公开成员函数)</span> </td></tr>

<tr class="t-dsc">
<td>  <div class="t-dsc-member-div"><div><a href="atomic/operator_T.html" title="cpp/atomic/atomic/operator T"> <span class="t-lines"><span>operator T</span></span></a></div></div>
</td>
<td>  从原子对象加载值 <br> <span class="t-mark">(公开成员函数)</span> </td></tr>

<tr class="t-dsc">
<td>  <div class="t-dsc-member-div"><div><a href="atomic/exchange.html" title="cpp/atomic/atomic/exchange"> <span class="t-lines"><span>exchange</span></span></a></div></div>
</td>
<td>  原子地替换原子对象的值并获得它先前持有的值 <br> <span class="t-mark">(公开成员函数)</span> </td></tr>

<tr class="t-dsc">
<td>  <div class="t-dsc-member-div"><div><a href="atomic/compare_exchange.html" title="cpp/atomic/atomic/compare exchange"> <span class="t-lines"><span>compare_exchange_weak</span><span>compare_exchange_strong</span></span></a></div></div>
</td>
<td>  原子地比较原子对象与非原子参数的值，若相等则进行交换，若不相等则进行加载 <br> <span class="t-mark">(公开成员函数)</span> </td></tr>

<tr class="t-dsc">
<td>  <div class="t-dsc-member-div"><div><a href="atomic/wait.html" title="cpp/atomic/atomic/wait"> <span class="t-lines"><span>wait</span></span></a></div><div><span class="t-lines"><span><span class="t-mark-rev t-since-cxx20">(C++20)</span></span></span></div></div>
</td>
<td>  阻塞线程直至被提醒且原子值更改 <br> <span class="t-mark">(公开成员函数)</span> </td></tr>

<tr class="t-dsc">
<td>  <div class="t-dsc-member-div"><div><a href="atomic/notify_one.html" title="cpp/atomic/atomic/notify one"> <span class="t-lines"><span>notify_one</span></span></a></div><div><span class="t-lines"><span><span class="t-mark-rev t-since-cxx20">(C++20)</span></span></span></div></div>
</td>
<td>  提醒至少一个在原子对象上的等待中阻塞的线程 <br> <span class="t-mark">(公开成员函数)</span> </td></tr>

<tr class="t-dsc">
<td>  <div class="t-dsc-member-div"><div><a href="atomic/notify_all.html" title="cpp/atomic/atomic/notify all"> <span class="t-lines"><span>notify_all</span></span></a></div><div><span class="t-lines"><span><span class="t-mark-rev t-since-cxx20">(C++20)</span></span></span></div></div>
</td>
<td>   提醒所有在原子对象上的等待中阻塞的线程 <br> <span class="t-mark">(公开成员函数)</span> </td></tr>

<tr>
<td colspan="2"> <h3> <span class="mw-headline" id=".E5.B8.B8.E9.87.8F"> 常量</span></h3>
</td></tr>

<tr class="t-dsc">
<td>  <div class="t-dsc-member-div"><div><a href="atomic/is_always_lock_free.html" title="cpp/atomic/atomic/is always lock free"> <span class="t-lines"><span>is_always_lock_free</span></span></a></div><div><span class="t-lines"><span><span class="t-cmark">[静态]</span> <span class="t-mark-rev t-since-cxx17">(C++17)</span></span></span></div></div>
</td>
<td>   指示该类型是否始终免锁 <br> <span class="t-mark">(公开静态成员常量)</span> </td></tr>
</table>
<h3><span class="mw-headline" id=".E7.89.B9.E5.8C.96.E6.88.90.E5.91.98.E5.87.BD.E6.95.B0">特化成员函数</span></h3>
<table class="t-dsc-begin">

<tr class="t-dsc">
<td>  <div class="t-dsc-member-div"><div><a href="atomic/fetch_add.html" title="cpp/atomic/atomic/fetch add"> <span class="t-lines"><span>fetch_add</span></span></a></div></div>
</td>
<td>  原子地将参数加到存储于原子对象的值，并返回先前保有的值 <br> <span class="t-mark">(公开成员函数)</span> </td></tr>

<tr class="t-dsc">
<td>  <div class="t-dsc-member-div"><div><a href="atomic/fetch_sub.html" title="cpp/atomic/atomic/fetch sub"> <span class="t-lines"><span>fetch_sub</span></span></a></div></div>
</td>
<td>  原子地从存储于原子对象的值减去参数，并获得先前保有的值 <br> <span class="t-mark">(公开成员函数)</span> </td></tr>

<tr class="t-dsc">
<td>  <div class="t-dsc-member-div"><div><a href="atomic/fetch_and.html" title="cpp/atomic/atomic/fetch and"> <span class="t-lines"><span>fetch_and</span></span></a></div></div>
</td>
<td>  原子地进行参数和原子对象的值的逐位与，并获得先前保有的值 <br> <span class="t-mark">(公开成员函数)</span> </td></tr>

<tr class="t-dsc">
<td>  <div class="t-dsc-member-div"><div><a href="atomic/fetch_or.html" title="cpp/atomic/atomic/fetch or"> <span class="t-lines"><span>fetch_or</span></span></a></div></div>
</td>
<td>  原子地进行参数和原子对象的值的逐位或，并获得先前保有的值  <br> <span class="t-mark">(公开成员函数)</span> </td></tr>

<tr class="t-dsc">
<td>  <div class="t-dsc-member-div"><div><a href="atomic/fetch_xor.html" title="cpp/atomic/atomic/fetch xor"> <span class="t-lines"><span>fetch_xor</span></span></a></div></div>
</td>
<td>  原子地进行参数和原子对象的值的逐位异或，并获得先前保有的值  <br> <span class="t-mark">(公开成员函数)</span> </td></tr>

<tr class="t-dsc">
<td>  <div class="t-dsc-member-div"><div><a href="atomic/operator_arith.html" title="cpp/atomic/atomic/operator arith"> <span class="t-lines"><span>operator++</span><span>operator++<span class="t-dsc-small">(int)</span></span><span>operator--</span><span>operator--<span class="t-dsc-small">(int)</span></span></span></a></div></div>
</td>
<td>  令原子值增加或减少一 <br> <span class="t-mark">(公开成员函数)</span> </td></tr>

<tr class="t-dsc">
<td>  <div class="t-dsc-member-div"><div><a href="atomic/operator_arith2.html" title="cpp/atomic/atomic/operator arith2"> <span class="t-lines"><span>operator+=</span><span>operator-=</span><span>operator&amp;=</span><span>operator|=</span><span>operator^=</span></span></a></div></div>
</td>
<td>  加、减，或与原子值进行逐位与、或、异或 <br> <span class="t-mark">(公开成员函数)</span> </td></tr>
</table>
<h3><span class="mw-headline" id=".E6.B3.A8.E8.A7.A3">注解</span></h3>
<p>存在等价于 <code>std::atomic</code> 所有成员函数的非成员函数模板。这些非成员函数可以额外对非 <span class="t-lc"><strong class="selflink">std::atomic</strong></span> 特化的类型重载，但不能保证原子性。标准库中仅有的这种类型是 <span class="t-c"><span class="mw-geshi cpp source-cpp"><a href="../memory/shared_ptr.html"><span class="kw734">std::<span class="me2">shared_ptr</span></span></a><span class="sy1">&lt;</span>U<span class="sy1">&gt;</span></span></span> 。
</p><p>gcc 和 clang 上，此处描述的某些功能要求通过 <code>-latomic</code> 链接。
</p>
<h3><span class="mw-headline" id=".E7.BC.BA.E9.99.B7.E6.8A.A5.E5.91.8A">缺陷报告</span></h3>
<p>下列更改行为的缺陷报告追溯地应用于以前出版的 C++ 标准。
</p>
<table class="dsctable" style="font-size:0.8em">
<tr>
<th> DR
</th>
<th> 应用于
</th>
<th> 出版时的行为
</th>
<th> 正确行为
</th></tr>
<tr>
<td> <a rel="nofollow" class="external text" href="https://cplusplus.github.io/LWG/issue2441">LWG 2441</a>
</td>
<td> C++11
</td>
<td>
</td>
<td> 添加了<span class="t-mark">(可选)</span><a href="../types/integer.html" title="cpp/types/integer">定宽整数类型</a>的特化
</td></tr>
<tr>
<td> <a rel="nofollow" class="external text" href="https://wg21.link/P0558R1">P0558R1</a>
</td>
<td> C++11
</td>
<td>
</td>
<td> 实质上重写了规定以解决数个问题
</td></tr>
<tr>
<td> <a rel="nofollow" class="external text" href="https://cplusplus.github.io/LWG/issue3012">LWG 3012</a>
</td>
<td> C++11
</td>
<td> <code>std::atomic&lt;T&gt;</code> 对任何可平凡复制但非可复制的 <code>T</code> 容许
</td>
<td> 禁止这种特化
</td></tr></table>
<h3><span class="mw-headline" id=".E5.8F.82.E9.98.85">参阅</span></h3>
<table class="t-dsc-begin">

<tr class="t-dsc">
<td>  <div class="t-dsc-member-div"><div><a href="atomic_flag.html" title="cpp/atomic/atomic flag"> <span class="t-lines"><span>atomic_flag</span></span></a></div><div><span class="t-lines"><span><span class="t-mark-rev t-since-cxx11">(C++11)</span></span></span></div></div>
</td>
<td>  免锁的布尔原子类型 <br> <span class="t-mark">(类)</span> </td></tr>
</table>
<h3><span class="mw-headline" id=".E5.BC.95.E7.94.A8">引用</span></h3>
<div class="t-ref-std-c++11">
<ul><li> C++11 standard (ISO/IEC 14882:2011): 
</li></ul>
<dl><dd><ul><li> 29.5 Atomic types [atomics.types.generic]
</li></ul>
</dd></dl>
</div>

<!-- 
NewPP limit report
Preprocessor visited node count: 13410/1000000
Preprocessor generated node count: 18194/1000000
Post‐expand include size: 298458/2097152 bytes
Template argument size: 73360/2097152 bytes
Highest expansion depth: 22/40
Expensive parser function count: 0/100
-->

<!-- Saved in parser cache with key mwiki1-mwiki_zh_:pcache:idhash:1490-0!*!0!!zh!*!zh!* and timestamp 20200209041700 -->
</div>                    <!-- /bodycontent -->
                                        <!-- printfooter -->
                    <div class="printfooter">
                    来自“<a href="https://zh.cppreference.com/mwiki/index.php?title=cpp/atomic/atomic&amp;oldid=64593">https://zh.cppreference.com/mwiki/index.php?title=cpp/atomic/atomic&amp;oldid=64593</a>”                    </div>
                    <!-- /printfooter -->
                                                            <!-- catlinks -->
                    <!-- /catlinks -->
                                                            <div class="visualClear"></div>
                    <!-- debughtml -->
                                        <!-- /debughtml -->
                </div>
                <!-- /bodyContent -->
            </div>
        </div>
        <!-- /content -->
        <!-- footer -->
        <div id="cpp-footer-base" class="noprint">
            <div id="footer">
                        <div id="cpp-navigation">
            <h5>导航</h5>
            <ul><li><a href="https://zh.cppreference.com/w/cpp/atomic/atomic">Online version</a></li><li>Offline version retrieved 2020-03-14 18:00.</li></ul></div>
                        <ul id="footer-info">
                                    <li id="footer-info-lastmod"> 本页面最后修改于2020年2月8日 (星期六) 20:17。</li>
                                    <li id="footer-info-viewcount">此页面已被浏览过70,162次。</li>
                            </ul>
                    </div>
        </div>
        <!-- /footer -->
        <script>if(window.mw){
mw.loader.state({"site":"loading","user":"missing","user.groups":"ready"});
}</script>
<script src="../../../common/skin_scripts.js"></script>
<script>if(window.mw){
mw.loader.load(["mediawiki.action.view.postEdit","mediawiki.user","mediawiki.page.ready","mediawiki.searchSuggest","mediawiki.hidpi","ext.gadget.MathJax","ext.gadget.ColiruCompiler"], null, true);
}</script>
<script src="../../../common/site_scripts.js"></script>
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-2828341-1']);
_gaq.push(['_setDomainName', 'cppreference.com']);
_gaq.push(['_trackPageview']);
</script><!-- Served in 0.079 secs. -->
	</body>
<!-- Cached 20200209044807 -->
</html>